<template>
	<view class="box" :style="theme">
		<!-- 会员卡 -->
		<view class="boxImg"
			:style="{backgroundImage: userInfo.cardPicPath?'url(' + userInfo.cardPicPath + ')':'url(' + coverImgUrl + ')'}">
			<view class="box_box">
				<view class="box_image_title">
					<view class="box_image_title_left">
						<view class="box_image_title_left_img">
							<image :src="userInfo.showAvatar ? userInfo.showAvatar : imgHost+'/user.png'"></image>
						</view>
						<view class="box_image_title_left_name"><text>{{userInfo.nickName}}</text></view>
					</view>
					<view class="box_image_title_right" v-if="userInfo.cardName"><text>{{userInfo.cardName}}</text>
					</view>
				</view>
				<view class="box_image_ye">
					<view>账户余额：</view>
					<view><text class="big">{{userInfo.money}}</text>元</view>
				</view>
			</view>
		</view>
		<!-- 充值金额 -->
		<view class="box_czje">
			<text class="box_czje_title">充值金额</text>
			<view class="box_czje_content">
				<view v-for="(item, index) in money" :key="index"
					:class="id === item.name?'box_czje_content_item active' :'box_czje_content_item'"
					@click="clickMoney(item)">
					<view class="bj"></view>
					<image v-if="id === item.name" :src="imgHost+'/vipcard_ic_select.png'"></image>
					<text v-if="item.name !== '自定义金额'">￥{{item.name}}</text>
					<text v-if="item.name == '自定义金额'" class="zdy">{{item.name}}</text>
				</view>
				<view class="box_czje_content_items"></view>
			</view>
			<view class="box_czje_input" v-if="id == '自定义金额'">
				<input class="weui-input" type="number" v-model="price" placeholder="输入充值金额" />
				<view class="box_czje_input_z">元</view>
			</view>
		</view>
		<!-- 展位 -->
		<view class="box_x"></view>
		<!-- 底部充值 -->
		<view class="box_footer">
			<view class="box_footer_agree">
				<view class="checkboxBox" :class="isActive?'on':''" @click="isTy">
					<u-icon v-if="isActive" name="checkmark-circle-fill" size="40rpx"></u-icon>
				</view>
				<view>充值即视为同意<text class="ztColor" @click="showxy">《充值协议》</text></view>
			</view>
			<view class="box_footer_btn" @click="$noMultipleClicks(submit)">
				<text>确认充值</text>
			</view>
		</view>
		<u-popup :show="agreement" @close="showxy" mode="center" round="20rpx">
			<view class="agreement">
				<view class="agreement_bt">充值协议</view>
				<scroll-view class="swiper-scroll" scroll-y="true">
					<u-parse :content="xy"></u-parse>
				</scroll-view>
				<view class="agreement_foot flex">
					<view style="opacity: 1" @click='showxy'>确定</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				noClick: true,
				agreement: false,
				coverImgUrl: 'http://zhcg-pro.oss-cn-hangzhou.aliyuncs.com/xiaochengxuditu/lQLPJyJX7wp-AgTNAU7NArKwOIDWsY44SlADqI0THYD_AA_690_334.png',
				isActive: false,
				money: [], //会员卡列表
				id: '', //会员卡id
				vipId: '', //会员id
				xy: ''
			}
		},
		onLoad(ops) {
			this.getYx()
			this.getMemberInformation()
		},
		methods: {
			showxy() {
				this.agreement = !this.agreement
			},
			getMemberInformation() {
				this.$app.ajax({
					data: {
						param: {}
					},
					api: this.$api.memberInformation()
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.$store.commit('saveUserInfo', res.record);
					}
				}).catch(() => {})
			},
			isTy(e) {
				this.isActive = !this.isActive
			},
			// 确认充值
			submit() {
				if (!this.isActive) {
					this.$app.showToast('请先同意协议')
					return false
				}
				if (!this.id) {
					this.$app.showToast('请先选择充值金额')
					return false
				}
				let that = this
				this.$app.ajax({
					data: {
						userId: this.userInfo.id,
						param: {
							money: this.id == '自定义金额' ? this.price : this.id,
							memberId: this.userInfo.id,
							venueId: this.venueId
						}
					},
					api: this.$api.memberRecharge()
				}).then((res) => {
					if (res.errorCode == '000000') {
						let orderId = res.record
						if (res.record) {
							this.$app.ajax({
								data: {
									userId: this.userInfo.id,
									param: {
										memberId: this.userInfo.id,
										orderId,
										integralUse: '0',
										payMethod: '03'
									}
								},
								api: this.$api.getPrice()
							}).then((resb) => {
								if (resb.errorCode === '000000') {
									let policyId = resb.record.policyId
									this.$app.ajax({
										data: {
											param: {
												orderId: orderId,
												payMethod: '03',
												integralUse: '0',
												policyId
											}
										},
										api: this.$api.payment()
									}).then((resc) => {
										if (resc.errorCode === '000000') {
											let data = resc.record
											uni.getProvider({
												service: 'payment',
												success: function(res) {
													uni.requestPayment({
														provider: 'wxpay', // 服务提提供商
														timeStamp: data
															.timeStamp,
														nonceStr: data
															.nonceStr,
														package: data
															.packageStr,
														signType: 'MD5',
														paySign: data.sign,
														success: function() {
															// 支付成功回调
															that.$app
																.showToast(
																	'支付成功')
															setTimeout(
																() => {
																	that.jump('/pages/home/index', '', 1)
																}, 2000
															)
															// 支付成功通知。。。
														},
														fail: function(errb) {

														}
													});
												}
											});

										} else {
											this.$app.showToast(resc.errorMsg || resc.msg)
										}
									}).catch(() => {})
								} else {
									if (resb.errorCode == '70003') {
										setTimeout(() => {
											that.jump('/pages/index/index','', 1)
										}, 2000)
									}
									this.$app.showToast(resb.errorMsg || resb.msg)
								}
							}).catch(() => {})
						}
					}
				}).catch(() => {})
			},
			// 选择金额
			clickMoney(e) {
				this.id = e.name
				this.price = ''
			},
			getYx() {
				this.$app.ajax({
					data: {
						param: {
							type: '15',
							code: 'AGREEMENT_RECHARGE'
						}
					},
					api: this.$api.paymentConfiguration()
				}).then((res) => {
					if (res.errorCode === '000000') {
						this.xy = res.recordList[0].value
					}
				}).catch(() => {})
				this.$app.ajax({
					data: {
						param: {
							type: '5'
						}
					},
					api: this.$api.paymentConfiguration()
				}).then((res) => {
					if (res.errorCode === '000000') {
						let arr = res.recordList
						let obj = {
							name: '自定义金额',
							id: 'wz'
						}
						arr.push(obj)
						this.money = arr
						this.id = arr[0].name
					}
				}).catch(() => {})
			},
		},
	}
</script>
<style>
	page {
		background: #fff;
	}
</style>
<style lang="scss" scoped>
	.box {
		padding: 30rpx;
		box-sizing: border-box;
	}

	.box .boxImg {
		width: 100%;
		height: 334rpx;
		position: relative;
		background-repeat: no-repeat;
		background-size: 100% 100%;
		background-position: center center;
	}

	.box_image_title_left {
		display: flex;
		align-items: center;
	}

	.box_box_vip {
		position: absolute;
		right: 0;
		bottom: 0;
	}

	.box_box {
		width: 100%;
		height: 100%;
		padding: 40rpx;
		box-sizing: border-box;
		position: absolute;
		top: 0;
		left: 0;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.box_image_title {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.box_image_title_left_img {
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		background: #ffffff;
		overflow: hidden;
	}

	.box_image_title_left_img image {
		width: 100%;
		height: 100%;
	}

	.box_image_title_left_name {
		margin-left: 32rpx;
	}

	.box_image_title_left_name text {
		font-size: 36rpx;
		font-weight: 500;
		color: $yellow;
	}

	.box_image_title_right {
		padding: 7rpx 16rpx;
		background: $yellow;
		border-radius: 8rpx;
	}

	.box_image_title_right text {
		font-size: 22rpx;
		font-weight: 400;
		color: #5A1900;
	}

	.box_image_ye {
		display: flex;
		flex-direction: column;
		view{
			font-size: 26rpx;
			font-weight: 400;
			color: $yellow;
			text {
				font-size: 48rpx;
				font-family: PingFangSC-Semibold, PingFang SC;
				font-weight: 600;
				margin-right: 8rpx;
				color: $yellow;
			}
		}
	}

	.box_czje {
		display: flex;
		flex-direction: column;
		margin-top: 48rpx;
	}

	.box_czje_title {
		font-size: 32rpx;
		font-weight: 600;
		color: #222222;
	}

	.box_czje_content {
		display: flex;
		margin-top: 32rpx;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.box_czje_content_items {
		width: calc(100% / 3.3);
	}

	.box_czje_content_item {
		width: calc(100% / 3.3);
		padding: 48rpx 0;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		border-radius: 16rpx;
		background: $bjColor;
		border: 2rpx solid #EEEEEE;
		margin-bottom: 26rpx;
		overflow: hidden;
		position: relative;
	
		image {
			width: 56rpx;
			height: 56rpx;
			position: absolute;
			right: 0;
			bottom: 0;
		}
	
		text {
			font-size: 40rpx;
			font-weight: 500;
			color: #666666;
		}
		.bj {
			position: absolute;
			left: 0;
			top: 0;
			right: 0;
			bottom: 0;
			background-color: $color;
			z-index: 0;
			display: none;
		}
	
		&.active {
			border-radius: 16rpx;
			border: 2rpx solid $color;
			.bj {
				display: block;
				opacity: 0.2;
			}
			text {
				color: #333;
			}
		}
	
	}
	

	.zdy {
		font-size: 26rpx !important;
	}

	.box_czje_input {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 98rpx;
		padding: 20rpx;
		box-sizing: border-box;
		background: $bjColor;
		border-radius: 16rpx;
		border: 2rpx solid $color;
	}

	.box_czje_input_z {
		width: 30rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #222222;
		margin-left: 15rpx;
	}

	.weui-input {
		flex: 1 !important;
	}

	.box_x {
		height: 230rpx;
	}

	.box_footer {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		width: 100%;
		height: 200rpx;
		background: #ffffff;
		padding: 30rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
	}

	.box_footer_agree {
		display: flex;
		align-items: center;
	}
	
	.box_footer_agree text {
		font-size: 26rpx;
		margin-left: 5rpx;
	}
	

	
	.box_footer_btn {
		height: 88rpx;
		background: $color;
		border-radius: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 20rpx;
	}
	
	.box_footer_btn text {
		font-size: 30rpx;
		font-weight: 500;
		color: #FFFFFF;
	}
</style>
